import { actorCalled } from '@serenity-js/core';
import { Ensure, not } from '@serenity-js/assertions';
import { useSystemAs } from '../../src/screenplay/abilities';
import { createARecordOf } from '../../src/screenplay/interactions';
import { existsInOrg } from '../../src/screenplay/expectations';
import { recordOf } from '../../src/salesforce';
import { ActualSalesforceRecord } from '../../src/screenplay/questions/saleforceRecord';

describe('API user can', () => {
  it('create account', () =>
    actorCalled('Joey')
      .whoCan(useSystemAs('Sales'))
      .attemptsTo(
        createARecordOf('Account').withFields({
          Name: 'Test Account',
        }),
        Ensure.that(
          ActualSalesforceRecord.like(
            recordOf('Account').withFields({
              Name: 'Test Account',
            })
          ),
          existsInOrg()
        )
      ));

  it('check that account does not exist', () =>
    actorCalled('Joey')
      .whoCan(useSystemAs('Sales'))
      .attemptsTo(
        Ensure.that(
          ActualSalesforceRecord.like(
            recordOf('Account').withFields({
              Name: 'Non exostent Account',
            })
          ),
          not(existsInOrg())
        )
      ));
});
